﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.ComponentModel;
using Xceed.Silverlight.Data;
using System.Collections.Generic;

namespace Xceed.Silverlight.DataGrid
{
  public class GroupContext
  {
    internal GroupContext(
      bool isBottomLevel,
      GroupDescription groupDescription,
      DataGridPath groupPath,
      EstimateInt64 itemCount,
      IEnumerable<object> items )
    {
      if( groupPath == null )
        throw new ArgumentNullException( "groupPath" );

      if( groupDescription == null )
        throw new ArgumentNullException( "groupDescription" );

      if( !( groupPath.ActualDataPath.LastChild is GroupDataItem ) )
        throw new ArgumentException( "The last child of the group path must be a GroupDataItem.", "groupPath" );

      this.IsBottomLevel = isBottomLevel;
      this.GroupDescription = groupDescription;
      this.GroupPath = groupPath;
      m_itemCount = itemCount;
      this.Items = items;
    }

    #region IsBottomLevel

    public bool IsBottomLevel
    {
      get;
      private set;
    }

    #endregion IsBottomLevel

    #region GroupDescription Property

    public GroupDescription GroupDescription
    {
      get;
      private set;
    }

    #endregion GroupDescription

    #region Path Property

    public DataGridPath GroupPath
    {
      get;
      private set;
    }

    #endregion Path

    #region GroupValue Property

    public object GroupValue
    {
      get
      {
        return this.GroupPath.ActualDataPath.LastChild.Data;
      }
    }

    #endregion GroupValue

    #region Items

    public IEnumerable<object> Items
    {
      get;
      private set;
    }

    #endregion Items

    #region ItemCount

    public Nullable<long> ItemCount
    {
      get
      {
        return ( m_itemCount != null )
         ? m_itemCount.Value
         : ( Nullable<long> )null;
      }
    }

    public bool IsItemCountEstimated
    {
      get
      {
        return ( m_itemCount != null )
          ? m_itemCount.IsEstimate
          : false;
      }
    }

    #endregion ItemCount

    private EstimateInt64 m_itemCount = null;



  }
}
